import {
  queryDraw,
  queryTableList,
  queryTableList2,
} from '@/services/sensitiveData/draw';

export default {
  namespace: 'draw',
  state: {
    treeData: {},
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    data2: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
  },

  effects: {
    *queryDraw({ payload, callback }, { call, put }) {
      const response = yield call(queryDraw, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response)
    },

    *queryTableList({ payload }, { call, put }) {
      const response = yield call(queryTableList, payload);
      yield put({
        type: 'saveTable',
        payload: response,
      });
    },

    *queryTableList2({ payload }, { call, put }) {
      const response = yield call(queryTableList2, payload);
      yield put({
        type: 'saveTable2',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        treeData: action.payload,
      };
    },

    saveTable(state, action) {
      return {
        ...state,   
        data: action.payload,//mock模拟
      };
    },

    saveTable2(state, action) {
      return {
        ...state,   
        data2: action.payload,//mock模拟
      };
    },
  },
};
